﻿@model LeadVinaglue.Models.ViewPages.EmailManagementModel
           
@{
    ViewBag.Title = "Xem e-mail";
    Layout = "~/Views/Shared/_Layout.Management.cshtml";
}

<form method="post" class="form" action="/Management/EmailList/Edit/@ViewBag.EmailTemplateId">
	<fieldset id="firstStep">
		<h2 class="app">
	        <strong>Xem mẫu e-mail</strong>
        </h2>		
		<div class="errorMessage" style="display:none" >
			<span class="error">Xin hãy nhập thông tin chính xác.</span>
		</div>	
		<div class="title">
			<h3>Thông tin email</h3>
		</div>
		<div class="columns">
            <input type="hidden" id="emailId" value="@ViewBag.EmailTemplateId" />
			<div class="col columnedit">                 
				<div class="row">
					<label>Gửi tới địa chỉ:</label>
                    <a href="javascript:PopupNewWindow('/Management/EmailList/PopupEmail', 'resizeble=0,scrollbar=0', 500, 400);">Chọn địa chỉ</a>
					<input type="button" id="SendEmailNotice" class="btn btn-submit-page" value="Submit" />
				</div>
                <div class="row">
					<textarea class="text" id="ToEmailAddress" name="ToEmailAddress" rows="5" cols="80" style="width: 100%"></textarea>
                </div>
				<div class="row" style="border-bottom:dashed 1px #ccc">
					<label>Loại email:</label>
				</div>
                <div class="row">
					<span>@Model.EmailInfo.EmailType</span>
                </div>
				<div class="row" style="border-bottom:dashed 1px #ccc">
					<label>Tiêu đề:</label>
				</div>
                <div class="row">
					<span>@Model.EmailInfo.SubjectLine</span>
                </div> 
				<div class="row" style="border-bottom:dashed 1px #ccc">
					<label>Nội dung gửi</label>
				</div>
                <div class="row">
                    <div class="LongDesc" style="overflow:hidden; width:770px;">@Html.Raw(Model.EmailInfo.Body)</div>
                </div>  
			</div>
		</div> 

        <!-- button below -->
		<div class="foot-info">
			<h3 class="centered-wbtn centered-wbtn-bottom save">
  				<span>
  					<a class="btn btn-cancel-page" href="/Management/EmailList">previous</a>
                </span>
			</h3>
		</div>
	</fieldset>
</form>

<script type="text/javascript">
    var data = @(Html.Raw(Json.Encode(Model)));
</script>
<script src="/TinyMCE/tiny_mce.js" type="text/javascript"></script>
<script src="/TinyMCE/tinymce.init.js" type="text/javascript"></script>
<script type="text/javascript">
    $('#SendEmailNotice').click(function () {
        // Json post
        var emailid = $('#emailId').val();
        var emailaddress = $('#ToEmailAddress').val();
        var url = "/Management/EmailList/SendEmailNotice";
        var data = {
            "id": emailid,
            "emailaddress": emailaddress
        };

        // Json Get function to retrive data from server
        $('.waiting').remove();
        $('#apps').waiting();
        $('.waiting').show();
        $('#progress').css("display", "block");

        // Messages
        $('.errorMessage').hide();

        $.post(url, data, function (model) {
            if (model != undefined && model != null && model != "") {
                $('.errorMessage').show();
                $('.errorMessage').find('.error').html(model);
            }
            else {

                $('.errorMessage').show();
                $('.errorMessage').find('.error').text("Gửi mail thành công");
                $('#ToEmailAddress').val('');
            }
            // Stop progress bar
            $('.waiting').hide();
            $('#progress').css("display", "none");

        });
    });
</script>